<?php
    include APPLICATION_PATH . '/application/views/head.phtml';
    include APPLICATION_PATH . '/application/views/top.phtml';
    include APPLICATION_PATH . '/application/views/left.phtml';
?>
 
<script src="/public/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
    var __ArtiForm = $('#form_article_add');
    var __editForm = $('#form_modal_edit');
    $('#submit_form').click(function() {

        var objArtiForm = {
            __formUrl: $("#push_address", __ArtiForm),
            __formName: $("input[name='push_module']", __ArtiForm)
        }
        for (var i in objArtiForm) {

            if (objArtiForm[i].val() == '') {
                objArtiForm[i].css({
                    'border-color': 'red'
                });
                return false;
            } else {
                objArtiForm[i].css({
                    'border-color': '#e5e5e5'
                });
            }
        }

        $.ajax({
            type: "POST",
            url: "/Category/add",
            data: {
                "catname": objArtiForm.__formName.val(),
                "siteid": objArtiForm.__formUrl.val()
            },
            success: function(data) {
                layer.alert(data.info, function() {
                    if (true === data.status) window.location = "/Category/list";
                });
            }
        });

    });

    $(document).on('click', '.tableDelete', function() {
        var userId = $(this).parent('td').attr('item_id'),
            thisUrl = $(this).attr('href');
        //官网欢迎页   
        layer.confirm('确认删除', {
            btn: ['确认', '取消'] //按钮
        }, function(index) {

            $.ajax({
                type: "GET",
                url: thisUrl,
                async: true,
                data: {
                    //"id" : userId
                },
                success: function(data) {
                    layer.alert(data.info, function() {
                        if (true === data.status) window.location = "/Category/list";
                    });
                }
            });
            layer.close(index);
            return false;

        }, function(index) {
            layer.close(index);
        });
        return false;

    });

    $(document).on('click', '.tableEdit', function(e) {

        $('#form_modal_edit').modal();
        var urlOld = $(this).attr('href'),
            urlArr = urlOld.split("/");
        urlId = urlArr[urlArr.length - 1];
        // $(this).attr({'href':'#form_modal_edit','data-toggle':'modal','data-target':'#form_modal_edit'});
        itemId = $(this).parent('td').attr('item_id');
        var __parent = $(this).parent('td').parent('tr.gradeX');
        objEditForm = {

            __formUrl: $("#pushAddress", __editForm),
            __formName: $('#pushModule')
                //__formTime : $('#create_time')
        };
        var tdTable = [];
        $('td', __parent).each(function() {
            tdTable.push($(this).text());
        });
        objEditForm.__formName.val(tdTable[1]);

        objEditForm.__formUrl.val(tdTable[0]);
        //objEditForm.__formTime.val(tdTable[2]);
        //

        $('option', objEditForm.__formUrl).each(function() {
            alert($(this).data('id'));
            if ($(this).data('id') == itemId) {
                $(this).attr('selected', true);
            }
        });
        return false;

    });


    $('#edit_form').click(function() {
        var objAuthForm = {
            __formName: $("input[name='pushModule']", __editForm),
            __formUrl: $("#pushAddress", __editForm)
        }
        for (var i in objAuthForm) {

            if (objAuthForm[i].val() == '') {
                objAuthForm[i].css({
                    'border-color': 'red'
                });
                return false;
            } else {
                objAuthForm[i].css({
                    'border-color': '#e5e5e5'
                });
            }

        }
        $.ajax({
            type: "POST",
            url: "/Category/edit/id/" + urlId,
            data: {
                "name": objAuthForm.__formName.val(),
                "sites_id": 　objAuthForm.__formUrl.val()
                    // "create_time" :　objAuthForm.__formTime.val(),

            },
            success: function(data) {
                layer.msg(data.info, function() {
                    if (true === data.status) window.location = "/Category/list";
                });
            },
            error: function(error) {
                alert('error');
            }
        });

    });

    //var nextBtn = $('#page_next');
    $(document).on('click', '#page_next,#page_prev,#page_index,#page_end', function() {
        var urlOld = $(this).attr('href'),
            urlArr = urlOld.split("/");
        urlId = urlArr[urlArr.length - 1];
        $.ajax({
            type: 'POST',
            url: '/Category/page/page/' + urlId,
            data: urlId,
            success: function(data) {
                var data = $.parseJSON(data);
                $('#tbody').html('');
                var id = '';

                $.each(data, function(k, v) {
                    //console.log('k='+k);
                    //id = k;

                    $.each(v, function(kk, vv) {

                       //console.log('kk='+kk,'vv='+vv['name']);
                      id = vv['cat_id'];
                        $('#tbody').append($('<tr class="gradeX"><td>' + vv['url'] + '</td><td>' + vv['name'] + '</td><td>' + vv['create_time'] + '</td><td item_id="' + vv['sites_id'] + '" cate_id="' + id + '"><a class="tableDelete" href="/Category/del/id/' + id + '">删除</a> / <a class="tableEdit" href="/Category/edit/id/' + id + '">修改</a> </td></tr>'));
                    });

                });

                //$('#tbody')
            }

        });
        $.ajax({
            type: 'POST',
            url: '/Category/currentPage/page/' + urlId,
            data: urlId,
            success: function(data) {
                //console.log(data);
                $('#pages').html(data);
                $('#pages').ready(function() {
                    nextBtn = $('#page_next');
                });
            }

        });
        return false;
    });

});
</script>
<div id="thispage" data-id="81"></div>


        <!-- END SIDEBAR -->

        <!-- BEGIN PAGE -->

        <div class="page-content">

            <!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

            <div id="portlet-config" class="modal hide">

                <div class="modal-header">

                    <button data-dismiss="modal" class="close" type="button"></button>

                    <h3>portlet Settings</h3>

                </div>

                <div class="modal-body">

                    <p>Here will be a configuration form</p>

                </div>

            </div>

            <!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->

            <!-- BEGIN PAGE CONTAINER-->        

            <div class="container-fluid">

                <!-- BEGIN PAGE HEADER-->

                <div class="row-fluid">

                    <div class="span12">

                        <!-- BEGIN STYLE CUSTOMIZER -->

                        <div class="color-panel hidden-phone">

                            <!-- <div class="color-mode-icons icon-color"></div> -->

                            <div class="color-mode-icons icon-color-close"></div>

                            <div class="color-mode">

                                <p>THEME COLOR</p>

                                <ul class="inline">

                                    <li class="color-black current color-default" data-style="default"></li>

                                    <li class="color-blue" data-style="blue"></li>

                                    <li class="color-brown" data-style="brown"></li>

                                    <li class="color-purple" data-style="purple"></li>

                                    <li class="color-grey" data-style="grey"></li>

                                    <li class="color-white color-light" data-style="light"></li>

                                </ul>

                                <label>

                                    <span>Layout</span>

                                    <select class="layout-option m-wrap small">

                                        <option value="fluid" selected>Fluid</option>

                                        <option value="boxed">Boxed</option>

                                    </select>

                                </label>

                                <label>

                                    <span>Header</span>

                                    <select class="header-option m-wrap small">

                                        <option value="fixed" selected>Fixed</option>

                                        <option value="default">Default</option>

                                    </select>

                                </label>

                                <label>

                                    <span>Sidebar</span>

                                    <select class="sidebar-option m-wrap small">

                                        <option value="fixed">Fixed</option>

                                        <option value="default" selected>Default</option>

                                    </select>

                                </label>

                                <label>

                                    <span>Footer</span>

                                    <select class="footer-option m-wrap small">

                                        <option value="fixed">Fixed</option>

                                        <option value="default" selected>Default</option>

                                    </select>

                                </label>

                            </div>

                        </div>

                        <!-- END BEGIN STYLE CUSTOMIZER -->  

                        <!-- BEGIN PAGE TITLE & BREADCRUMB-->

                        <h3 class="page-title">

                            栏目管理 

                        </h3>

                        <ul class="breadcrumb">

                            <li>

                                <i class="icon-home"></i>
                                <span>当前位置：</span>
                                <span>首页</span>

                                <i class="icon-angle-right"></i>

                            </li>

                            <li>

                                <span>栏目管理</span>

                                <i class="icon-angle-right"></i>

                            </li>

                            <li><span>中华盛世</span></li>

                        </ul>

                        <!-- END PAGE TITLE & BREADCRUMB-->

                    </div>

                </div>

                <!-- END PAGE HEADER-->

                <!-- BEGIN PAGE CONTENT-->

                <div class="row-fluid">

                    <div class="span6 responsive" data-tablet="span12 fix-offset" data-desktop="span6" style="width:100%;">

                        <!-- BEGIN EXAMPLE TABLE PORTLET-->

                        <div class="portlet box grey">

                            <div class="portlet-title">

                                <div class="caption"><i class="icon-user"></i>中华盛世</div>

                                <div class="actions controls">

                                    <!-- <a href="#form_modal_tj"  data-toggle="modal" data-target="#form_modal_tj" class="btn blue"><i class="icon-pencil"></i> 添加</a> -->

                                </div>

                            </div>

                            <div class="portlet-body" style="height: 565px; overflow: scroll;overflow-x:hidden">

                                <table class="table table-striped table-bordered table-hover" id="current_table">

                                    <thead>

                                        <tr>
                                            <th>网站名称</th>
                                            <th>推送栏目</th>
                                            
                                            <!-- <th>操作</th> -->
                                        </tr>

                                    </thead>

                                <tbody id="tbody">
<?php
    $this->WebsiteModel   = new WebsiteModel();
    foreach ($list_info as $key => $value) {
        $childid = explode(",",$value['arrchildid']);
        $childLength = count ($childid);
            if($value['parentid'] == 0){
                 echo <<< EOF
                    <tr class="{$style} gradeX">
                        <td>中华盛世</td>
                        <td>{$value['catname']} </td>
                    </tr>
EOF;
/* <td item_id="{$v['siteid']}"><a class="tableDelete" href="/Category/del/id/{$value['catid']}">删除</a> / <a class="tableEdit" href="/Category/edit/id/{$value['catid']}">修改</a></td>*/
                if($childLength>1){
                    foreach ($childid as $kc => $vc) {
                        $rs = $this->WebsiteModel->getZhssInfoByParentid($vc);
                        if($kc!=0 ){
                            foreach ($rs as $ks => $vs) {
                                $catid = explode(",",$vs['arrparentid']);
                                $catLength = count ($catid);
                                if($catLength == 2){
                                echo <<< EOF
                                    <tr class="{$style} gradeX">
                                        <td>中华盛世</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;├─  {$vs['catname']} </td>
                                    </tr>
EOF;
                                }
                                $child_id = explode(",",$vs['arrchildid']);
                                $childLen = count ($child_id);
                                if($childLen>1){
                                    foreach ($child_id as $kd => $vd) {
                                        $res = $this->WebsiteModel->getZhssInfoByParentid($vd);
                                        if($kd!=0){
                                            foreach ($res as $kes => $ves) {
                                                $childrenId = explode(",",$ves['arrparentid']);
                                                $childrenIdLength = count ($childrenId);
                                                if($childrenIdLength == 3){
                                                    echo <<< EOF
                                                        <tr class="{$style} gradeX">
                                                            <td>中华盛世</td>
                                                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│ &nbsp;&nbsp;&nbsp;&nbsp;├─  {$ves['catname']} </td>
                                                        </tr>
EOF;
                                                }
                                                $child_four = explode(",",$ves['arrchildid']);
                                                $childLenFour = count ($child_four);
                                                if($childLenFour>1){
                                                    foreach ($child_four as $kh => $vh) {
                                                        $result = $this->WebsiteModel->getZhssInfoByParentid($vh);
                                                        if($kh!=0){
                                                            foreach ($result as $ket => $vet) {
                                                                $childrenIdFour = explode(",",$vet['arrparentid']);
                                                                $childrenIdLengthFour = count ($childrenIdFour);
                                                                if($childrenIdLengthFour == 4){
                                                                    echo <<< EOF
                                                                        <tr class="{$style} gradeX">
                                                                            <td>中华盛世</td>
                                                                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─  {$vet['catname']} </td>
                                                                        </tr>
EOF;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } 
                    }
                }
        }
          
    }
    
?>

                                    </tbody>

                </table>



                            </div>

                        </div>
                                       
                                <div id="form_modal_tj" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

                                    <div class="modal-header">

                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

                                        <h3 id="myModalLabel3">添加一级栏目列表</h3>

                                    </div>

                                    <div class="modal-body">

                                        <form action="#" id="form_article_add" method="post" class="form-horizontal">
                                         <div class="control-group">

                                                <label class="control-label">推送地址</label>

                                                <div class="controls">

                                                     <select class="colorpicker-default m-wrap" name="push_address" id="push_address" >
<?php
     foreach ($sites_list AS $k => $v) {
         echo '<option value="'.$v['siteid'].'" data-id="' . $v['category_id'] . '">' . $v['name'] . '</option>';
     }
?> 
                                                    </select>


                                                </div>

                                            </div>


                                            <div class="control-group">


                                                <label class="control-label">推送栏目</label>

                                                <div class="controls">
                                                <input type="text" class="colorpicker-default m-wrap" name="push_module" value="" id="push_module">                                                  
                                                    

                                                </div>

                                            </div>

                                           

                                        </form>

                                    </div>
                 
                                    <div class="modal-footer">

                                        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

                                        <button class="btn green btn-primary" id="submit_form" data-dismiss="modal" >提交</button>

                                    </div>

                                </div>

                                <div id="form_modal_edit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

                                    <div class="modal-header">

                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

                                        <h3 id="myModalLabel3">修改一级栏目列表</h3>

                                    </div>

                                    <div class="modal-body">

                                        <form action="#" id="form_article_edit" method="post" class="form-horizontal">
                                        <div class="control-group">
                                            
                                            
                                                <div class="controls">
  
                                                </div>
                                            
                                            </div> 

                                            <div class="control-group">
                                            
                                                <label class="control-label">推送网站</label>
                                            
                                                <div class="controls">
                                            
                                                    <select class="colorpicker-default m-wrap" name="push_address" id="pushAddress" readonly="readonly">
<?php
    foreach ($sites_list AS $k => $v) {
        echo '<option value="'.$v['siteid'].'" data-id="' . $v['siteid'] . '">' . $v['name'] . '</option>';
    }
?> 
                                                        
                                                    </select>
                                            
                                                </div>
                                            
                                            </div> 

                                            
                                            
                                             <div class="control-group">
                                            
                                                <label class="control-label">推送栏目</label>
                                            
                                                <div class="controls">
                                                    <input type="text" class="colorpicker-default m-wrap" name="pushModule" value="" id="pushModule">

                                                    </select>
                                            
                                                </div>
                                            
                                            </div> 

                                           


                                        </form>

                                    </div>

                                    <div class="modal-footer">

                                        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

                                        <button class="btn green btn-primary" id="edit_form" data-dismiss="modal" >提交</button>
                                        
                                    </div>

                                </div>




                                


                        <!-- END EXAMPLE TABLE PORTLET-->

                    </div>

                </div>

                <!-- END PAGE CONTENT-->

            </div>

            <!-- END PAGE CONTAINER-->

        </div>

    <!-- END PAGE -->
<?php
    include APPLICATION_PATH . '/application/views/foot.phtml';
?>


